package com.shopoo.oauth.wap;

import java.security.KeyPair;
import java.security.interfaces.RSAPublicKey;
import java.util.Map;

import javax.annotation.Resource;

import com.nimbusds.jose.jwk.JWKSet;
import com.nimbusds.jose.jwk.RSAKey;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description: RSA公钥开放接口
 * @Auther: limy66
 * @Date: 2021/03/11/15:18
 */
@Api(tags = "RSA公钥开放接口")
@RestController
@RequestMapping("/rsa")
@Slf4j
public class PublicKeyController {

    @Resource
    private KeyPair keyPair;

    @GetMapping("/publicKey")
    public Map<String, Object> getPublicKey() {
        log.info("获取公钥！");
        RSAPublicKey publicKey = (RSAPublicKey) keyPair.getPublic();
        RSAKey key = new RSAKey.Builder(publicKey).build();
        return new JWKSet(key).toJSONObject();
    }
}
